D			[0-9]
L			[a-zA-Z_]

%{
#include <stdio.h>
#include "araGrammar.tab.h"

void count();
%}

%%
"/*"			{ comment(); }
"//"			{ cppComment(); }
"else"			{ count(); return(ELSE); }
"if"			{ count(); return(IF); }
"int"			{ count(); return(INT); }
"return"		{ count(); return(RETURN); }
"void"			{ count(); return(VOID); }

{L}({L}|{D})*		{ count(); yylval.nom = (char *)strdup(yytext); return(IDENTIFICADOR); }

{D}+			{ count(); yylval.valor = atoi(yytext); return(CONSTANTE); }
L?\"(\\.|[^\\"])*\"	{ count(); yylval.nom = yytext; return(LITERAL_ALFANUMERICO); }

"++"			{ count(); return(INC_OP); }
"--"			{ count(); return(DEC_OP); }
";"			{ count(); return(';'); }
("{"|"<%")		{ count(); return('{'); }
("}"|"%>")		{ count(); return('}'); }
","			{ count(); return(','); }
"="			{ count(); return('='); }
"("			{ count(); return('('); }
")"			{ count(); return(')'); }
"-"			{ count(); return('-'); }
"+"			{ count(); return('+'); }
"*"			{ count(); return('*'); }
"/"			{ count(); return('/'); }
"%"			{ count(); return('%'); }

[ \t\v\n\f]		{ count(); }
.			{ printf("   //Error lexico, caracter '%s' desconocido//   ",yytext); }

%%

/* Elimina comentarios estilo C */
comment()
{
	char c, c1;

loop:
	while ((c = input()) != '*' && c != 0)
		;

	if ((c1 = input()) != '/' && c != 0)
	{	
		unput(c1);	
		goto loop;
	}

	if (c != 0)
		;
}

/* Elimina comentarios estilo C++ */
cppComment()
{
	char c;
	while ((c = input()) != '\n' && c != 0)
		;
}


int column = 0;

/* Muestra por pantalla programa de entrada */
/* Por ahora no voy a mostrar nada ya que causa confusion con las producciones por pantalla */
void count()
{
	int i;

	for (i = 0; yytext[i] != '\0'; i++)
		if (yytext[i] == '\n')
			column = 0;
		else if (yytext[i] == '\t')
			column += 8 - (column % 8);
		else
			column++;

	/* ECHO; */
}

